using System;
using System.Collections.Generic;
using System.Drawing;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.Samples.DirectX.UtilityToolkit;
using TTDotNet.Engine.ThreeDEngine;
using TTDotNet.Util;

namespace TTDotNet.Engine.GUI
{
    public class Background : Control
    {
        private Coordinate coord;
        private GameTexture texture;
        private Sprite s;

        float width, height;

        public Background(string path, GameTimer bTimer)
        {
            bTimer.Start();
            texture = Game.textureCacher.LoadTexture(path);
            bTimer.Stop();
            SetupStuff();
            
        }

        public Background(string path)
        {
            texture = Game.textureCacher.LoadTexture(path);
            SetupStuff();
        }

        public Background(GameTexture tex)
        {
            texture = tex;
            SetupStuff();
        }

        private void SetupStuff()
        {
            coord = new Coordinate();
            s = new Sprite(Game.device);
            width = texture.Texture.GetLevelDescription(0).Width;
            height = texture.Texture.GetLevelDescription(0).Height;
        }

        public void Render(Coordinate windowCoord)
        {
            s.Begin(SpriteFlags.None);
            s.Draw(texture.Texture, new Rectangle(0, 0, (int)width, (int)height), new Vector3(0.0f, 0.0f, 0.0f),
                            new Vector3(coord.X + windowCoord.X, coord.Z + windowCoord.Z, 0.0f), Color.White);
            s.End();
        }

        public void UpdatePosition(Coordinate coord)
        {
            this.coord = coord;
        }

        public override void SetSize(float width, float height)
        {
            this.width = width;
            this.height = height;
        }

        public void ScaleBy(float factor)
        {
            this.width = (int)((float)this.width * factor);
            this.height = (int)((float)this.height * factor);
        }

        public int Width
        {
            get { return width; }
        }

        public int Height
        {
            get { return height; }
        }

        public Texture Texture
        {
            get { return texture.Texture; }
        }

    }
}
